<?php

$current_page = 'edit_news';

include 'inc_header.php';
include 'inc_menu.php';

//Redirect if User is not logged on
if(!isset($_SESSION["username"]))
{
	header("location: index.php");
}

//Check for Insert News-Request
if(isset($_POST['insertnews']))
{
	$connection = new DAOmySQLi();
	$connection->insertNews();
}

//Check for Insert News-Request
if(@$_REQUEST['action']=="delnews")
{
	$connection = new DAOmySQLi();
	$connection->deleteNews();
}
?>

<div id="main">
	<div class="ym-wrapper">
		<div class="ym-wbox">
		
			<!-- Insert News Form -->
			<h3>Edit news - Insert new one</h3>
			<form class="ym-form ym-columnar linearize-form" action=edit_news.php
				method=post enctype=multipart/form-data>
				<div class="ym-fbox-text">
					<label for="titel">Titel:</label> <input type="text" name="newsTitel" id="insert-text-news" value="" />
				</div>
				<div class="ym-fbox-text">
					<label for="author">Author:</label>
					<?php  $connection = new DAOmySQLi(); $connection->getDropdown_NewsAuthor(); ?>
				</div>
				<div class="ym-fbox-text">
					<label for="story">Story:</label>
					<textarea name="newsStory" id="insert-area-news" cols="30" rows="7"></textarea>
				</div>
				<div class="ym-fbox-button">
					<button class="ym-button ym-add" type="submit" name="insertnews" id="insert-button">Insert</button>
				</div>
			</form>

			<!-- News in Database -->
			<h3>Edit news - Delete old news</h3>
			
			<?php
				//Generate Table
				$connection->getEditNews();						
			?>		
										
		</div>
	</div>
</div>


<?php 
include 'inc_footer.php';
?>